//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#include <bsp.h>
#include <mmu.h>
#include <lcd.h>

const uint_t c_uMaxNumberOfMemoryZones          = 2;
const uint_t c_uMaxNumberOfMemoryHoles          = 1;

EXTERN_C_BEGIN

STATIC DECL_DATAINIT MemoryZone    s_memoryZones[c_uMaxNumberOfMemoryZones];
STATIC DECL_DATAINIT MemoryHole    s_memoryHoles[c_uMaxNumberOfMemoryHoles];

EXTERN_C_END

static DECL_CODEINIT void GetInitStack();
STATIC DECL_CODEINIT void GetMemoryZones();

EXTERN_C DECL_CODEINIT void CDECL InitMemoryZones()
{
    GetInitStack();

    GetMemoryZones();
}

static DECL_CODEINIT void GetInitStack()
{
    bsp.regionOfInitStack.uBasePageNo =
        PHYSADDR_TO_PAGENO(0xc0000000
            + RoundUp2(c_uLCDFrameBufferSize, PAGE_SIZE));
    bsp.regionOfInitStack.uLimitPageNo = PHYSADDR_TO_PAGENO(0xc0010000);
}

static DECL_CODEINIT void GetMemoryZones()
{
    bsp.pMemoryZones = s_memoryZones;
    bsp.pMemoryHoles = s_memoryHoles;

    s_memoryZones[0].uBasePageNo    = PHYSADDR_TO_PAGENO(0xc0000000);
    s_memoryZones[0].uLimitPageNo   = PHYSADDR_TO_PAGENO(0xc0800000);
    s_memoryZones[1].uBasePageNo    = PHYSADDR_TO_PAGENO(0xc1000000);
    s_memoryZones[1].uLimitPageNo   = PHYSADDR_TO_PAGENO(0xc1800000);
    bsp.uNumberOfMemoryZones = 2;

    bsp.uDmaPreferredZoneNo = 0;
    bsp.uKernelPreferredZoneNo = 1;
    bsp.uUserPreferredZoneNo = 1;

    // Hole 0 for video frame buffer
    s_memoryHoles[0].uBasePageNo    = PHYSADDR_TO_PAGENO(0xc0000000);
    s_memoryHoles[0].uLimitPageNo   =
        PHYSADDR_TO_PAGENO(0xc0000000
            + RoundUp2(c_uLCDFrameBufferSize, PAGE_SIZE));
    bsp.uNumberOfMemoryHoles = 1;
}
